package com.webshopping.service.order;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webshopping.entry.ShopCar;
import com.webshopping.entry.SubOrder;
import com.webshopping.mapper.SubOrderMapper;

@Service
public class SubOrderService {
	
	@Autowired
	private SubOrderMapper soMapper;
	
	/**
	 * 
	 * @param info
	 * @return
	 */
	public  List<SubOrder>  getSubOrserInfo(String[] info){
		 List<SubOrder> subOrder = new ArrayList<SubOrder>();
		 String shopCarIdList;
	        for(String s:info){
	        	//System.out.println(s);
	    	   String[] oneSubOrder = s.split(",");
	    	   System.out.println(oneSubOrder.length);
	    	   SubOrder so = new SubOrder();	    	  
	    	   so.setCommodityId(Integer.parseInt(oneSubOrder[0]));
	    	   so.setNum(Integer.parseInt(oneSubOrder[1]));
	    	   //shopCarIdList.add(oneSubOrder[1]);
	    	   so.setShopCarIdList(oneSubOrder[2]);
	    	   subOrder.add(so);
	    	   
	        }
	            //System.out.println(subOrders);
	            return subOrder;
	}
	
	
	 public int add(SubOrder subOrder){
		 return soMapper.add(subOrder);
	 }
		public int delete(int sid){
			return soMapper.delete(sid);
		}

}
